﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 软构第一次作业
{
    public partial class Form2 : Form
    {
        private static string s = "abcd";
        private static int[] n;
        private static int choice = 0;
        public Form2()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }


        private void button1_Click(object sender, EventArgs e)
        {
            string[] d =
              textbox.Text.Trim().Split(new char[] { ' '});


            // 将字串数组转换成整数
            n = new int[d.Length];
            try
            {
                for (int i = 0; i < d.Length; i++)
                {
                    n[i] = int.Parse(d[i].Trim());
                }
            }
            catch
            {
                MessageBox
                  .Show("输入的必须是数字且数字中间用空格隔开！");
                return;
            }
            choice = 1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] d =
              textbox.Text.Trim().Split(new char[] { ' '});


            // 将字串数组转换成整数
            n = new int[d.Length];
            try
            {
                for (int i = 0; i < d.Length; i++)
                {
                    n[i] = int.Parse(d[i].Trim());
                }
            }
            catch
            {
                MessageBox
                  .Show("输入的必须是数字且数字中间用空格或逗号隔开！");
                return;
            }
            choice = 2;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string[] d =
              textbox.Text.Trim().Split(new char[] { ' '});


            // 将字串数组转换成整数
            n = new int[d.Length];
            try
            {
                for (int i = 0; i < d.Length; i++)
                {
                    n[i] = int.Parse(d[i].Trim());
                }
            }
            catch
            {
                MessageBox
                  .Show("输入的必须是数字且数字中间用空格或逗号隔开！");
                return;
            }
            choice = 3;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string[] d =
              textbox.Text.Trim().Split(new char[] { ' '});


            // 将字串数组转换成整数
            n = new int[d.Length];
            try
            {
                for (int i = 0; i < d.Length; i++)
                {
                    n[i] = int.Parse(d[i].Trim());
                }
            }
            catch
            {
                MessageBox
                  .Show("输入的必须是数字且数字中间用空格或逗号隔开！");
                return;
            }
            choice = 4;
        }

        private void textbox_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }

        private void button5_Click(object sender, EventArgs e)
        {
            demo p = new demo();
            if (choice != 0)
            {
                switch (choice)
                {
                    case 1:
                        s = "求最大值的结果为" + p.Getmax(n);
                        break;
                    case 2:
                        s = "求最小值的结果为" + p.Getmin(n);
                        break;
                    case 3:
                        s = "求平均值的结果为" + p.Getavg(n);
                        break;
                    case 4:
                        s = "求元素和的结果为" + p.Getsum(n);
                        break;
                }
                this.textBox1.Text = s;
            }
        }
    }
}
